package cn.lzx;

import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;
import javax.sql.DataSource;

/**
 * @author lizhenxing
 * 2019/6/20 上午11:22
 */
@Configuration
@EnableConfigurationProperties(DataSourceProperty.class)
public class DataSourceAutoConfiguration {

    @Resource
    private DataSourceProperty property;

    @Bean
    public DataSource dataSource() {
        return DataSourceBuilder.create()
                .type(DruidDataSource.class)
                .username(property.getUsername())
                .password(property.getPassword())
                .url(property.getUrl())
                .build();
    }
}
